package com.paomi.client.activity.person.Adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.person.InvitationActivity;
import com.paomi.client.activity.person.model.TaskListDetailBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyPointAdapter extends RecyclerView.Adapter<MyPointAdapter.ViewHolder> {
    private Context context;
    private List<TaskListDetailBean> data = new ArrayList<>();
    private onItemClickListener onItemClick;

    public MyPointAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<TaskListDetailBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    public void setOnItemClick(onItemClickListener onItemClick) {
        this.onItemClick = onItemClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_my_points, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("NewApi")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (position < data.size()) {
            TaskListDetailBean entity = data.get(position);
            holder.tv_msg.setText(entity.getName());
            if (entity.isComplete()) {
                holder.tv_btn.setText("已完成");
                holder.tv_btn.setTextColor(context.getResources().getColor(R.color.black));
                holder.tv_btn.setBackground(context.getResources().getDrawable(R.drawable.ellipse_btn_gray));
            } else {
                holder.tv_btn.setText("去完成");
                holder.tv_btn.setTextColor(context.getResources().getColor(R.color.color_108EE9));
                holder.tv_btn.setBackground(context.getResources().getDrawable(R.drawable.ellipse_btn_blue));
            }
            holder.tv_point.setText("+" + entity.getIntegral());
            holder.tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClick!=null){
                        onItemClick.OnItemClick(v,position);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_msg)
        TextView tv_msg;
        @BindView(R.id.tv_point)
        TextView tv_point;
        @BindView(R.id.tv_btn)
        TextView tv_btn;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    public interface onItemClickListener{
        void OnItemClick(View view,int position);
    }
}
